<template>
	<!-- 项目发布 -->
	<view class="bg-white container mt-2 h4">
		<u--form labelPosition="top" :model="msgFrom" ref="msgFrom" labelWidth="80" :rules="rules">
			<view class="img_warp">
				<u-form-item label="企业介绍" prop="content">
					<textarea class="textarea mt-2 p-1" maxlength="-1" v-model="msgFrom.content" placeholder="请输入企业介绍"></textarea>
				</u-form-item>
			</view>
			<view class="img_warp">
				<u-form-item label="宣传视频" prop="video">
					<u-upload
						:fileList="videoCont"
						@afterRead="afterRead"
						@delete="deletePic"
						name="video"
						:maxCount="1"
						accept="video"
						:compressed="true"
						camera="back"
						:previewImage="true"
					></u-upload>
					<video v-if="msgFrom.video" :src="msgFrom.video" style="height: 395rpx;min-width: 700rpx;width: 100% !important;"></video>
				</u-form-item>
			</view>
		</u--form>
	</view>
</template>

<script>
import { uploadImage } from '@/api/common.js';
export default {
	data() {
		return {
			msgFrom: {
				content: '',
				video: ''
			},
			videoCont: [],
			rules: {
				content: [
					{
						type: 'string',
						required: true,
						message: '请输入企业介绍',
						trigger: ['blur', 'change']
					}
				]
			}
		};
	},
	methods: {
		deletePic(event) {
			this.videoCont.splice(0, 1);
			this.msgFrom.video = '';
		},
		async afterRead(event) {
			uploadImage(event)
				.then(res => {
					if (res.code == 0) {
						this.videoCont.push({ url: res.img });
						this.msgFrom.video = this.videoCont[0].url;
					} else {
						uni.$u.toast(res.msg);
					}
				})
				.catch(err => {
					console.log('视频上传失败');
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.textarea {
	width: 100%;
	height: 220rpx;
	background: #ffffff;
	border: 1px solid #c0c0c0;
}
</style>
